/*
 * @Author: zwc 6537397+uni-yunApp@user.noreply.gitee.com
 * @Date: 2023-03-15 18:07:50
 * @LastEditors: zwc 6537397+uni-yunApp@user.noreply.gitee.com
 * @LastEditTime: 2023-03-17 17:29:25
 * @FilePath: \project-template\src\store\modules\user\user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import {userState} from './type'
import router from '@/router'
import fetchApi from '@/api/user/user'
 const useUserStore = defineStore('user', {
  // 推荐使用 完整类型推断的箭头函数
  state: ():userState => {
    return {
      // 所有这些属性都将自动推断其类型
      userInfo:{},
      token:'xxx',
      permissionList:[]
    }
  },
  actions:{
    //获取用户信息
    getUserInfo(){
    try {
      return new Promise(async(resolve,reject)=>{
        const res = await fetchApi.getUserInf()
        console.log('运行了吗')
        if(res.data.result){
          this.userInfo = res.data.result
          this.permissionList = res.data.result.authorityResults
          resolve(true)
        }else{
          reject(false)
        }
      })
     
      
    } catch (error) {
      
    }
      
    }
  }
})

export default useUserStore